from PIL import Image


def SavePicFromNumpy(data, filename):
    """data: 3 * h * w numpy"""
    rows = data.shape[1]
    cols = data.shape[2]
    im = Image.new("RGB", (cols, rows))
    pix = im.load()
    assert data.shape[0] == 3
    for i in range(rows):
        for j in range(cols):
            pix[j, i] = (data[0, i, j], data[1, i, j], data[2, i, j])
    im.save(filename)


def SavePicFromNumpy1(data, filename):
    """data: 3 * h * w numpy"""
    rows = 678
    cols = 224
    im = Image.new("RGB", (cols, rows))
    pix = im.load()
    for i in range(rows / 2):
        for j in range(cols):
            pix[j, i] = (255, 0, 0)
    im.save(filename)

if __name__ == '__main__':
    SavePicFromNumpy1('1', '1.jpg')
